package com.fms.controller;

import com.fms.result.ResultData;
import com.fms.entity.Orders;
import com.fms.service.OrdersService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/order")
@RequiredArgsConstructor
public class OrdersController {

    private final OrdersService ordersService;

    //新增或更新订单
    @PostMapping("/addOrSaveOrder")
    public ResultData addOrSaveOrder(@RequestBody Orders orders){
        System.out.println(orders);
        ordersService.addOrSaveOrder(orders);
        return ResultData.success("Order added successfully");
    }

    //获取所有订单
    @GetMapping("/getOrders")
    public ResultData getOrders(){
        List<Orders> list = ordersService.getOrders();
        return ResultData.success(list);
    }

    //获取指定订单
    @GetMapping("/getOrder/{id}")
    public ResultData getOrders(@PathVariable("id") Long id){
        Orders order = ordersService.getOrder(id);
        return ResultData.success(order);
    }

    //删除订单
    @PostMapping("/deleteOrder/{id}")
    public ResultData deleteOrder(@PathVariable("id") String id){
        System.out.println(id);
        ordersService.deleteOrder(id);
        return ResultData.success("shit");
    }

    //流转订单
    @PostMapping("/transferOrder")
    public ResultData transferOrder(@RequestBody Orders orders){
        ordersService.transferOrder(orders);
        return ResultData.success("shit");
    }

    //更新订单材料
    @PostMapping("/updateOrderMaterial")
    public ResultData updateOrderMaterial(@RequestBody Orders orders){
        ordersService.updateOrderMaterial(orders);
        System.out.println(orders);
        return ResultData.success("shit");
    }

    //否决订单
    @PostMapping("/denyOrder")
    public ResultData denyOrder(@RequestBody Orders orders){
        ordersService.denyOrder(orders);
        return  ResultData.success("shit");
    }

    //通过订单
    @PostMapping("/passOrder")
    public ResultData passOrder(@RequestBody Orders orders){
        ordersService.passOrder(orders);
        return ResultData.success("shit");
    }

    //安装单
    @PostMapping("/equipmentConfirm")
    public ResultData equipmentConfirm(@RequestBody Orders orders){
        System.out.println(orders.getNote());
        ordersService.equipmentConfirm(orders);
        return ResultData.success("shit");
    }

    //出货单
    @PostMapping("/shipmentConfirm")
    public ResultData shipmentConfirm(@RequestBody Orders orders){
        ordersService.shipmentConfirm(orders);
        return ResultData.success("shit");
    }
}
